<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数</title>
</head>

<body>
    <script>
        // 1、声明
        function mySum1(x, y) {
            return x + y;
        }

        let mySum2 = function (x, y) {
            return x + y;
        };

        let mySum3 = (x, y) => {
            return x + y;
        };

        let mySum4 = (x, y) => x + y;

        console.log(mySum1(2, 3));
        console.log(mySum2(2, 3));
        console.log(mySum3(2, 3));
        console.log(mySum4(2, 3));

        (function () {
            console.log('Start11111');
        })();

        (function (x, y) {
            console.log(x + y);
        })(20, 30);




        // 2、作用域
        console.log(localParam)
        let localParam = 2;



        let globalParam = 1;
        function testParam() {
            globalParam = 2;
            return;
        }
        console.log(globalParam);
        testParam();
        console.log(globalParam);


        function testParam2() {
            let localParam = 2;
            return;
        }
        // console.log(localParam);

        let param = 1;
        function testParam3(x) {
            x = 2;
        }
        console.log(param);
        testParam3(param);
        console.log(param);

        let arr = [1];
        function testParam4(x) {
            x.push(2);
        }
        console.log(arr);
        testParam4(arr);
        console.log(arr);

    </script>
</body>

</html>